﻿namespace MRMDS.Module
{
    public class GlobalManager
    {
        private static GlobalManager? instance;
        public static GlobalManager Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new GlobalManager();
                }
                return instance;
            }
        }

        public Dictionary<string, string> Token2UUIDdic { get; set; }
        public Dictionary<string, Actor> UUID2Actor { get; set; }
        public Dictionary<string,Viewer> UUID2Viewer { get; set; }

        public GlobalManager()
        {
            Token2UUIDdic = new Dictionary<string, string>();
            UUID2Actor = new Dictionary<string, Actor>();
            UUID2Viewer = new Dictionary<string, Viewer>();
        }

        public void Reset()
        {
            Token2UUIDdic.Clear();
            UUID2Actor.Clear();
            UUID2Viewer.Clear();
        }

        public string GenerateUUID()
        {
            string uuid;
            do
            {
                uuid = Guid.NewGuid().ToString();
            } while (UUID2Actor.ContainsKey(uuid));
            return uuid;
        }
    }
}